/*	
 * Copyright (C) 2010  Mark Schyns
 * 
 * This file is part of Poker League Leaderboard.
 * 
 * Poker League Leaderboard is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Poker League Leaderboard is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Poker League Leaderboard.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.gambit727.pokerleagueleaderboard;

public class FSM {
	// Fields.
	private static State state;
	
	// Constructors.	
	public FSM() {
		reset();
	}

	// Methods.
	public static State getState() {
		return state;
	}

	public void reset() {
		state = State.BEGIN_FILE;
	}
	
	public void transition (Condition condition) {
		State newState = State.INVALID;
		
		switch (state) {
		case BEGIN_FILE :
			newState = transitionFromBeginFile(condition);
			break;
		case ON_TOURNAMENT_ID :
			newState = transitionFromOnTournamentId(condition);
			break;
		case ON_SATELLITE :
			newState = transitionFromOnSatellite(condition);
			break;
		case ON_BUY_IN :
			newState = transitionFromOnBuyIn(condition);
			break;
		case ON_FIELD_SIZE :
			newState = transitionFromOnFieldSize(condition);
			break;
		case ON_PRIZE_POOL :
			newState = transitionFromOnPrizePool(condition);
			break;
		case ON_TARGET :
			newState = transitionFromOnTarget(condition);
			break;
		case ON_TICKETS :
			newState = transitionFromOnTickets(condition);
			break;
		case ON_TIMESPAN :
			newState = transitionFromOnTimespan(condition);
			break;
		case ON_TIME_START :
			newState = transitionFromOnTimeStart(condition);
			break;
		case ON_TIME_FINISH :
			newState = transitionFromOnTimeFinish(condition);
			break;
		case ON_RESULT :
			newState = transitionFromOnResult(condition);
			break;
		case END_FILE :
			newState = State.END_FILE;
		}
		state = newState;
	}

	private static State transitionFromOnResult(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_RESULT :
			newState = State.ON_RESULT;
			break;
		case READ_END_FILE :
			newState = State.END_FILE;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnTimeFinish(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_RESULT :
			newState = State.ON_RESULT;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnTimeStart(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_TIME_FINISH :
			newState = State.ON_TIME_FINISH;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnTimespan(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_RESULT :
			newState = State.ON_RESULT;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnTickets(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_TIME_START :
			newState = State.ON_TIME_START;
			break;
		case READ_TIMESPAN :
			newState = State.ON_TIMESPAN;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnTarget(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_TICKETS :
			newState = State.ON_TICKETS;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnPrizePool(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_TIMESPAN :
			newState = State.ON_TIMESPAN;
			break;
		case READ_TARGET :
			newState = State.ON_TARGET;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnFieldSize(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_PRIZE_POOL :
			newState = State.ON_PRIZE_POOL;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnBuyIn(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_FIELD_SIZE :
			newState = State.ON_FIELD_SIZE;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnSatellite(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_BUY_IN :
			newState = State.ON_BUY_IN;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromOnTournamentId(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_BUY_IN :
			newState = State.ON_BUY_IN;
			break;
		case READ_SATELLITE :
			newState = State.ON_SATELLITE;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}

	private static State transitionFromBeginFile(Condition condition) {
		State newState;
		switch (condition) {
		case READ_BLANK :
			newState = getState();
			break;
		case READ_TOURNAMENT_ID :
			newState = State.ON_TOURNAMENT_ID;
			break;
		case READ_END_FILE :
			newState = State.END_FILE;
			break;
		default :
			newState = State.INVALID;
			break;
		}
		return newState;
	}
}
